package com.lottery.system.dao.mapper;
import com.lottery.system.dao.dataobject.ActivityDO;
import org.apache.ibatis.annotations.*;

import java.util.List;


/**
 * @author: xiaoxie
 * create: 2024-09-09 10:37
 * @BelongsProject: lottery-system
 * @BelongsPackage: com.lottery.system.dao.mapper
 * description: 活动的数据层
 */
@Mapper
public interface ActivityMapper {

    /**
     * @description: 插入活动信息
     * @author: xiaoxie
     * @date: 2024/9/9 18:36
     * @param: [activityDO]
     * @return: void
     **/
    @Insert("insert into activity(activity_name,description,status)" +
            " values(#{activityName},#{description},#{status})")
    @Options(useGeneratedKeys = true,keyProperty = "id",keyColumn = "id")
    void insert(ActivityDO activityDO);

    /**
     * @description: 获取活动列表总数
     * @author: xiaoxie
     * @date: 2024/9/9 22:34
     * @param: []
     * @return: int
     **/
    @Select("select count(*) from activity")
    int count();

    /**
     * @description: 获取活动列表分页
     * @author: xiaoxie
     * @date: 2024/9/9 22:35
     * @param: [offSet, pageSize]
     * @return: java.util.List<com.lottery.system.dao.dataobject.ActivityDO>
     **/
    @Select("select id,activity_name,description,status from activity " +
            "order by id desc limit #{offSet},#{pageSize}")
    List<ActivityDO> selectActivityList(Integer offSet, Integer pageSize);

    /**
     * @description: 通过活动id查询活动对象
     * @author: xiaoxie
     * @date: 2024/9/12 22:03
     * @param: [activityId]
     * @return: com.lottery.system.dao.dataobject.ActivityDO
     **/
    @Select("select id,activity_name,description,status from activity " +
            " where id = #{activityId}")
    ActivityDO selectActivityById(@Param(value = "activityId") Long activityId);

    /**
     * @description: 通过id改变活动状态
     * @author: xiaoxie
     * @date: 2024/9/12 22:04
     * @param: [activityId, name]
     * @return: void
     **/
    @Update("update activity " +
            " set status = #{status} " +
            " where id = #{activityId}")
    void updateStatusById(@Param(value = "activityId") Long activityId
                         ,@Param(value = "status") String status);
}
